unit uListaDependentes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, dxSkinsdxBarPainter, ZAbstractRODataset,
  ZAbstractDataset, ZAbstractTable, ZDataset, ZAbstractConnection, ZConnection,
  dxBar, cxClasses, ActnList, ImgList, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridCustomView, cxGrid, StdCtrls,
  Buttons, ExtCtrls, uDataModule, uCadastroDependente, uCadastroGenerico, Mask,
  DBCtrls, cxGridCustomPopupMenu, cxGridPopupMenu, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, cxDBLookupComboBox  ;

type
  TfListaDependentes = class(TForm)
    pnl1: TPanel;
    lbl37: TLabel;
    gbList: TGroupBox;
    cxgrdCliente: TcxGrid;
    gdDependentes: TcxGridDBTableView;
    cxgrdlvlcliente: TcxGridLevel;
    ImageList: TImageList;
    ActionList: TActionList;
    actAdicionar: TAction;
    actEditar: TAction;
    actRemover: TAction;
    actGravar: TAction;
    actDesfazer: TAction;
    actAjuda: TAction;
    actRelatorio: TAction;
    actDSPrimeiro: TAction;
    actDSAnterior: TAction;
    actDSProximo: TAction;
    actDSUltimo: TAction;
    actDSBuscar: TAction;
    dxBarManager: TdxBarManager;
    dxBarManagerBar2: TdxBar;
    dxBarLargeButton1: TdxBarLargeButton;
    dxBarLargeButton2: TdxBarLargeButton;
    dxBarLargeButton3: TdxBarLargeButton;
    dxBarSubItem1: TdxBarSubItem;
    btnAdicionar: TdxBarLargeButton;
    btnEditar: TdxBarLargeButton;
    btnRemover: TdxBarLargeButton;
    btnGravar: TdxBarLargeButton;
    btnDesfazer: TdxBarLargeButton;
    pnlLeft: TPanel;
    gbInfoClienteTitular: TGroupBox;
    lblTitular: TLabel;
    lblFoneTitular: TLabel;
    colDependentescod_dependente: TcxGridDBColumn;
    colDependentescpf: TcxGridDBColumn;
    colDependentesnome: TcxGridDBColumn;
    colDependentessexo: TcxGridDBColumn;
    colDependentesdatanascimento: TcxGridDBColumn;
    colDependentesparentesco: TcxGridDBColumn;
    colDependentesstatus: TcxGridDBColumn;
    colDependentescausa_falecimento: TcxGridDBColumn;
    colDependentesdata_falecimento: TcxGridDBColumn;
    dbedtNome: TDBEdit;
    dbedtFone: TDBEdit;
    dbedtFoneCel: TDBEdit;
    lblCelular: TLabel;
    cxpopgd: TcxGridPopupMenu;
    cxgrdbclmnDependentescod_cliente: TcxGridDBColumn;
    cxgrdbclmnDependentesobservacao: TcxGridDBColumn;
    procedure actEditarExecute(Sender: TObject);
    procedure actRemoverExecute(Sender: TObject);
    procedure gdDependentesMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure gdDependentesKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fListaDependentes: TfListaDependentes;

implementation

{$R *.dfm}

procedure TfListaDependentes.actEditarExecute(Sender: TObject);
var
  aFCadastro: TfCadastroDependente;
begin
  try
    aFCadastro:= TfCadastroDependente.Criar('dependentes','seqdependentes');
    aFCadastro.Modo := MCEdita;
    aFCadastro.IdRegistro := DataModule1.tblDependentes2.Fields[0].AsInteger;
    aFCadastro.dsTitular.DataSet := DataModule1.tblClientes2;
    aFCadastro.ShowModal;
  finally
    DataModule1.tblDependentes2.Refresh;
    aFCadastro.Free;
  end;
end;

procedure TfListaDependentes.actRemoverExecute(Sender: TObject);
begin
  if (MessageDlg('Deseja excluir o registro selecionado?', mtWarning, [mbYes, mbNo], 0) = mrYes) then
  begin
    DataModule1.RegisterEvent('Excluiu Dependente',DataModule1.tblDependentes2cpf.Value+ ' - '+ DataModule1.tblDependentes2nome.Value);
    DataModule1.tblDependentes2.Delete;
    DataModule1.tblDependentes2.ApplyUpdates;
    DataModule1.tblDependentes2.Refresh;
  end;
end;

procedure TfListaDependentes.FormShow(Sender: TObject);
begin
  gdDependentes.ApplyBestFit();
end;

procedure TfListaDependentes.gdDependentesKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    DataModule1.tblClientes2.Locate('cod_cliente' ,DataModule1.tblDependentes2.FieldByName('cod_cliente').AsInteger,[] );
end;

procedure TfListaDependentes.gdDependentesMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
    DataModule1.tblClientes2.Locate('cod_cliente' ,DataModule1.tblDependentes2.FieldByName('cod_cliente').AsInteger,[] );
end;

end.
